package cn.koala.key.receipt.controller;

import cn.koala.key.api.KeyManagementApi;
import cn.koala.key.api.ShopApi;
import cn.koala.key.common.feign.FeignUtils;
import cn.koala.key.complaint.entity.dto.CarRepairShopDTO;
import cn.koala.key.complaint.entity.dto.ShopItemInfoDTO;
import cn.koala.key.receipt.vo.CarRepairShop;
import cn.koala.key.receipt.vo.StoreVO;
import cn.seed.common.core.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 32415
 * @description: 获取门店信息
 * @time 2019/5/7
 **/
@RestController
public class ShopController {

    /**
     * @Description: 模糊查询门店信息
     *
     * @param
     * @return Object
     * @throws
     * @exception:
     * @author: 32415
     * @time: 2019/5/7 15:34
     */
    @GetMapping("/stores")
    public Result<List<StoreVO>> getShopLike(@RequestParam(required = false) Integer cityId, @RequestParam(required = false) int source) {
        return FeignUtils.getHttpApi(KeyManagementApi.class).getAllShops(source, cityId);
    }

    @GetMapping("/stores/{id}")
    public Result<CarRepairShop> getShopById(@PathVariable Integer id) {
        return FeignUtils.getHttpApi(KeyManagementApi.class).getShopById(id);
    }

    @ApiOperation(value = "查询所有门店")
    @GetMapping("/search/store")
    public Result<List<CarRepairShopDTO>> listShops(){
        return FeignUtils.getHttpApi(ShopApi.class).listShops();
    }

    @ApiOperation(value = "根据门店的名称模糊搜或者门店id精准匹配")
    @GetMapping("/car/repair/shop/fuzzyNameOrById")
    public Result<List<CarRepairShop>> getCarRepairShopFuzzyNameOrById(
            @RequestParam(required = false, value = "name") String name,
            @RequestParam(required = false, value = "id") Integer id) {
        return FeignUtils.getHttpApi(ShopApi.class).getCarRepairShopFuzzyNameOrById(name,id);
    }

    @ApiOperation(value = "根据城市,项目,排序筛选门店列表")
    @GetMapping("/shopByCityItemSort")
    public Result<List<ShopItemInfoDTO>> shopByCityItemSort(@RequestParam(required = false) Integer cityId,
                                                            @RequestParam Double latitude, @RequestParam Double longitude,
                                                            @RequestParam(defaultValue = "1") Integer pageNumber,
                                                            @RequestParam(defaultValue = "10") Integer pageSize) {
        return FeignUtils.getHttpApi(ShopApi.class).shopByCityAndSort(cityId, latitude, longitude, pageNumber, pageSize);
    }
}
